let ipts = document.querySelectorAll('input')
console.log(ipts);
let box = document.querySelector('.box')
let isusername = false
ipts[0].onblur = function () {
    let username = ipts[0].value
    let reg = /^[\u2E80-\u9FFF]+$/
    if (reg.test(username)) {
        box.innerHTML = '输入格式正确'
        isusername = true
    } else {
        isusername = false
        box.innerHTML = '输入格式错误'
    }
}
let isPhonenumber = false;
ipts[1].onblur = function () {
    let reg = /^(13[0-9]|14[0-9]|15[0-9]|18[0-9]|17[0-9])\d{8}$/
    if (reg.test(this.value)) {
        isPhonenumber = true
        this.nextElementSibling.innerHTML = '格式输入正确'
    } else {
        this.nextElementSibling.innerHTML = '格式输入错误'
    }
}
let quicly_reg = document.querySelector('.quicly_reg')
console.log(quicly_reg);
quicly_reg.onclick = function () {
    let username = ipts[0].value
    let password = ipts[1].value
    // console.log(1);
    if (isusername && isPhonenumber) {
        // 如果二者的输入框输入格式正确的话，发起注册请求
        let url = `http://jx.xuzhixiang.top/ap/api/login.php`
        axios.get(url, {
            params: {
                username,
                password
            }
        }).then((res) => {
            console.log(res);
            if (res.data.code == 0) {
                confirm(res.data.msg + '或者检查是否注册')
            }
            if (res.data.code == 1) {
                confirm(res.data.msg + '，请问是否立刻需要进入商品首页')
                localStorage.setItem('username', username)
                localStorage.setItem('password', password)
                localStorage.setItem('uid', res.data.data.id)
                localStorage.setItem('token', res.data.data.token)
                location.href = 'first_page.html'
            }
           
        })
    }
}